package com.hsylient.javase.chapter05;

import lombok.SneakyThrows;
import org.junit.Test;

import java.io.BufferedWriter;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.OutputStreamWriter;

/**
 * 带有缓冲区的字符输出流
 */
public class J_MyBufferedWriter {

    @Test
    @SneakyThrows
    public void testRead() {
        FileWriter fileWriter = new FileWriter("s.txt");
        BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        bufferedWriter.write("hsylient");
        bufferedWriter.flush();
        bufferedWriter.close();
    }

    @Test
    @SneakyThrows
    public void testTransform() {
        BufferedWriter bufferedWriter = new BufferedWriter(
                new OutputStreamWriter(
                        new FileOutputStream("hsylient.txt")));
        bufferedWriter.write("hsylient");
        bufferedWriter.flush();
        bufferedWriter.close();
    }
}
